﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace mqmake
{
    class Program
    {
        static void Main(string[] args)
        {
           
            ProjectParser pro = new ProjectParser("project.json");
            List<string> taskList = pro.GetTasks();
            Parallel.ForEach(taskList, item => {
                try
                {
                    string cc = item.Split(' ')[0] + ".exe";
                    string arg = item.Substring(item.Split(' ')[0].Length);
                    Process p = new Process();
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.WorkingDirectory = System.Environment.CurrentDirectory;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.RedirectStandardError = true;
                    p.StartInfo.FileName = cc;
                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.Arguments = arg;//参数以空格分隔，如果某个参数为空，可以传入””
                    p.Start();
                    p.WaitForExit();
                    string output = p.StandardOutput.ReadToEnd();
                    Console.WriteLine(output);
                    Console.WriteLine(p.StandardError.ReadToEnd());
                }
                catch (Exception)
                {
                    throw;
                }
            });
            string linkcmd = (pro.GetLinkCMD());
            string link = linkcmd.Split(' ')[0] + ".exe";
            string larg = linkcmd.Substring(linkcmd.Split(' ')[0].Length);
            Process pp = new Process();
            pp.StartInfo.UseShellExecute = false;
            pp.StartInfo.WorkingDirectory = System.Environment.CurrentDirectory;
            pp.StartInfo.RedirectStandardOutput = true;
            pp.StartInfo.RedirectStandardError = true;
            pp.StartInfo.FileName = link;
            pp.StartInfo.CreateNoWindow = true;
            pp.StartInfo.Arguments = larg;//参数以空格分隔，如果某个参数为空，可以传入””
            pp.Start();
            pp.WaitForExit();
            string output1= pp.StandardOutput.ReadToEnd();
            Console.WriteLine(output1);
            Console.WriteLine(pp.StandardError.ReadToEnd());
            
            Console.ReadKey();
        }
    }
}
